#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int maxn=100000;
namespace ac{
    int a[maxn],b[maxn];
    int n;
    //在下标区间[l,r]中
    int find(int l,int r,int num){
        if(l>r)return l;
        int mid=(l+r)>>1;
        if(b[mid]>=num){
            return find(l,mid-1,num);
        }
        else return find(mid+1,r,num);
    }
    int getmidnum(){
        int l=1,r=n;
        for(int i=1;i<=n;i++){
            int mid=find(l,r,a[i]);
            if(i+mid-1<n){l=mid;continue;}
            if(i+mid-1==n)return a[i];
            else return b[n-i+1];
        }
    }
};

int main()
{
    IOS;
    cout<<"数列长度:";
    cin>>ac::n;
    cout<<"数列a:"<<endl;
    for(int i=1;i<=ac::n;i++){
        cin>>ac::a[i];
    }
    cout<<"数列b:"<<endl;
    for(int i=1;i<=ac::n;i++){
        cin>>ac::b[i];
    }
    cout<<"中位数:"<<ac::getmidnum()<<endl;
    getchar();
    getchar();
    return 0;
}
